/**
 * Created by levy on 16/6/15.
 */
/**
 * @author created by hjm
 * @author edited by levy
 * @desc [显示信息行]
 * @param [tableTitList, data]
 * @tableTitList: 表单标题列表 [[objectKey,con],[objectKey,con]](二维数组)
 * @data: 数据
 */

{
    const DetailFormRow = React.createClass({
        render: function () {
            var props = this.props,
                field = props.field,
                content = props.tit && props.tit.indexOf('时间')  > -1
                    ? liefeng.utils.format(props.con,"yyyy-MM-dd hh:mm")
                    : props.con;

            console.log(content)
            //report-detail.js渲染逻辑
            if(field == 'reportMode') {
                content = content == 1 ? '来电' : content == 2 ? 'APP客户端' : '上门';
            }

            return (
                <div className={"detail-form-row " + (this.props.addClass || '')}>
                    <p className="detail-form-tit">{props.tit}：</p>
                    <aside className="break-word">{content || '无'}</aside>
                </div>
            )
        }
    });

    /**
     * @param data 必传
     * @param tableTitList 若不传，则走传type的逻辑
     * @param addClass 添加的类：text-left 文字左对齐
     *
     * add by levy
     * @param type 如果传了type 则不用传tableTitList 定义不同的渲染逻辑, 默认array
     * @param title 冒号左边的文字
     * @param text 冒号右边的文字
     *
     * 这种格式的文字详情
     * title1: text1
     * title2: text2
     * title3: text3
     */
    var TextDetail = React.createClass({
        getInitialState: function () {
            return {
            }
        },
        render: function () {
            var tit = this.props.tableTitList,
                dt = this.props.data,
                cls = this.props.addClass,
                type = this.props.type || 'array',
                title = this.props.title,
                text = this.props.text;
            console.log(tit)
            //原有的逻辑
            if(tit)
                var detailFormRows = tit.map(function ( item ) {
                    return <DetailFormRow tit={item[1]} con={dt[item[0]]} field={item[0]}
                        addClass={cls}/>
                });

            //新的渲染逻辑,默认array,需要时再添加 type 的判断
            else {
                var  detailFormRows = dt.map((item) => {
                    return <DetailFormRow tit={item[title]} con={item[text]}
                        addClass={cls}/>
                });
            }



            return (
                <div className="detail-form">
                    {detailFormRows}
                </div>
            )
        }
    });
}

export default TextDetail;
